package com.huahua.graduateschoolspringboot.controller;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.huahua.graduateschoolspringboot.entity.R;
import com.huahua.graduateschoolspringboot.entity.param.LightChangeStatusParam;
import com.huahua.graduateschoolspringboot.entity.po.CityLightConfig;
import com.huahua.graduateschoolspringboot.entity.po.CityLightDevice;
import com.huahua.graduateschoolspringboot.entity.vo.CityLightConfigVo;
import com.huahua.graduateschoolspringboot.service.CityLightConfigService;
import com.huahua.graduateschoolspringboot.service.CityLightDeviceService;
import com.huahua.graduateschoolspringboot.service.impl.CityLightDeviceServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LoveHuaHua
 * @date 2023年05月04日 11:23
 * @description believe in yourself
 */
@RestController
@RequestMapping("/light")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class LightController {

    private final CityLightConfigService cityLightConfigService;
    private final CityLightDeviceService cityLightDeviceService;

    @PostMapping("/updateMode")
    public Object updateMode(@RequestBody LightChangeStatusParam lightCustomDTO) throws JsonProcessingException {
        cityLightConfigService.updateMode(lightCustomDTO);
        return R.success();
    }


    @GetMapping("/getMode")
    public Object getMode() {
        List<CityLightConfig> list = cityLightConfigService.list();
        List<CityLightConfigVo> cityLightConfigVos = BeanUtil.copyToList(list, CityLightConfigVo.class);
        return R.success(cityLightConfigVos);
    }

    @GetMapping("/getDeviceStatus")
    public Object getAll() {
        List<CityLightDevice> list = cityLightDeviceService.list();
        return R.success(list);
    }
}
